/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.navid.trafalgar.camera;

import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.input.FlyByCamera;
import com.jme3.input.InputManager;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;
import java.io.IOException;

/**
 *
 * @author alberto
 */
public class TopCamera implements Control{

    Camera cam;
    Node reference;
    boolean enabled;

    public TopCamera(Camera cam, Node reference) {
        this.cam = cam;
        reference.addControl(this);
        this.reference = reference;
    }

    public void registerWithInput(InputManager inputManager) {
        //no input
    }

    @Override
    public void update(float tpf) {
        if (enabled) {
            Vector3f position = reference.getWorldTranslation();
            this.cam.setRotation(new Quaternion().fromAngles((float)Math.PI / 2, -(float)Math.PI / 2 , 0));
            this.cam.setLocation(new Vector3f(position.x, position.y + 300, position.z));
        }
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public Control cloneForSpatial(Spatial spatial) {
        return this;
    }

    public void setSpatial(Spatial spatial) {
    }

    public void render(RenderManager rm, ViewPort vp) {
    }

    public void write(JmeExporter ex) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void read(JmeImporter im) throws IOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean isEnabled() {
        return enabled;
    }
}
